<template>
	<view class="search">
		<uni-search-bar placeholder="请输入内容" @confirm="handleSearch"></uni-search-bar>
		
		
		<view class="histort-search">
			<text v-for="(item,index) in historySearch" :key="index">{{ item }}</text>
		</view>
		<view class="" v-if="searchResult.length === 0">
			<image src="../../static/images/no-result.png" mode="widthFix" style="width: 100%;"></image>
		</view>
		<view class="" v-else>
			<navigator v-for="(item, index) in searchResult" :key="index" :url="'/pages/detail/detail?id=' + item.id">
				<list-item :item="item">
					<template #word>
						{{ item.word }}
					</template>
				</list-item>
			</navigator>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				searchResult: [],
				historySearch: uni.getStorageSync('historySearch') || []
			};
		},
		methods: {
			handleSearch({
				value
			}) {
				uni.request({
					url: 'http://localhost:3000/list?q=' + value,
					success: resp => {
						this.searchResult = resp.data
					}
				})
				this.historySearch.unshift(value);
				uni.setStorageSync('historySearch', this.historySearch)
			}
		}
	}
</script>

<style lang="scss">
	.search {
		background-color: white;
		height: 100vh;
	}
</style>